using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Curriculum.Business;
using Curriculum.UI.Helper;
using Curriculum.Business.Manejadores;

namespace Curriculum.UI
{
	/// <summary>
	/// Summary description for frmVersiones.
	/// </summary>
	public class frmVersiones : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ListBox lstVersiones;
		private System.Windows.Forms.Button btnVer;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		//
		private Form instanceRef;

		public frmVersiones()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region - Custom Methods -

		private void CargarVersionesExistentes()
		{
			ListaDeVersiones versionesExistentes = ListaDeVersiones.GetInstancia();			
			Helper.ListHelper.FillListControl(lstVersiones,versionesExistentes.GetNumerosDeVersion());			
		}
		
		#endregion - Custom Methods -

		#region - Properties -
		

		public Form InstanceRef
		{
			get { return instanceRef; }
			set { instanceRef = value; }
		}

		#endregion - Properties -


		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmVersiones));
			this.lstVersiones = new System.Windows.Forms.ListBox();
			this.label1 = new System.Windows.Forms.Label();
			this.btnVer = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// lstVersiones
			// 
			this.lstVersiones.Location = new System.Drawing.Point(8, 40);
			this.lstVersiones.Name = "lstVersiones";
			this.lstVersiones.Size = new System.Drawing.Size(184, 134);
			this.lstVersiones.TabIndex = 0;
			this.lstVersiones.DoubleClick+=new EventHandler(lstVersiones_DoubleClick);
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(8, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(128, 23);
			this.label1.TabIndex = 1;
			this.label1.Text = "Versiones";
			// 
			// btnVer
			// 
			this.btnVer.Location = new System.Drawing.Point(64, 184);
			this.btnVer.Name = "btnVer";
			this.btnVer.TabIndex = 2;
			this.btnVer.Text = "&Ver";
			this.btnVer.Click += new System.EventHandler(this.btnVer_Click);
			// 
			// frmVersiones
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(200, 218);
			this.Controls.Add(this.btnVer);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.lstVersiones);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.ImeMode = System.Windows.Forms.ImeMode.Off;
			this.MaximizeBox = false;
			this.Name = "frmVersiones";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Versiones Disponibles";
			this.Load += new System.EventHandler(this.frmVersiones_Load);
			this.Closed += new System.EventHandler(this.frmVersiones_Closed);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmVersiones_Load(object sender, System.EventArgs e)
		{
			CargarVersionesExistentes();
		}

		private void btnVer_Click(object sender, System.EventArgs e)
		{
			Cursor.Current = Cursors.AppStarting;

			string idVersion = lstVersiones.SelectedValue.ToString();
			Curriculum cv = new Curriculum(idVersion);
			cv.InstanceRef = this;

			// inicializo el masterdata y el Manejador de Antecedentes
			MasterData.GetInstancia(idVersion);
			ManejadorAntecedentes.GetInstancia(idVersion);

			cv.ShowDialog();

			Cursor.Current = Cursors.Default;
		}

		public void Reset()
		{
			CargarVersionesExistentes();
		}

		private void frmVersiones_Closed(object sender, System.EventArgs e)
		{
			InstanceRef.Show();
			this.Close();
		}		

		private void lstVersiones_DoubleClick(object sender, EventArgs e)
		{
			if (lstVersiones.SelectedValue != null)
			{
				Cursor.Current = Cursors.AppStarting;
			
				string idVersion = lstVersiones.SelectedValue.ToString();
				Curriculum cv = new Curriculum(idVersion);
				cv.InstanceRef = this;

				// inicializo el masterdata y el Manejador de Antecedentes
				MasterData.GetInstancia(idVersion);
				ManejadorAntecedentes.GetInstancia(idVersion);

				cv.ShowDialog();

				Cursor.Current = Cursors.Default;		
			}
		}
	}
}
